<?php

namespace app\home\controller;

use app\common\controller\Frontend;
use think\Controller;
use think\Request;
use think\Db;
use think\Cache;
use fast\lucn\Lucn;

//use think\Db;

/**
 * 首页
 *
 * @icon fa fa-circle-o
 */
class Review extends Base
{
    protected $model = null;

    public function _initialize()
    {
		define('SIGN', 'review');//定义标识
		define('TABLE', 'review');//定义数据表名。
		$this->assign('controller_sign',SIGN);
		$this->assign('controller_page','追溯');
        parent::_initialize();
    }
	
	public function tolist()
    {
		//article
		//define('TABLE_2', 'category');//定义数据表名。
		//define('PTYPE_2', '');//定义类别
		$cid = input('?cid') ? input('cid') : '';
		$category = Cache::get('cache')['category'];
		$category_article = Lucn::getCategoryFromType($category,SIGN);
		if(input('?cid')){
		    $category_one = Lucn::getCategoryFromType($category_article,$cid,'id');
			$where['category_id'] = $cid;
		}else{
		    $category_one = '';
		}
		//dump($category_one);die;
		$where['status'] = 'normal';
	    $list = Db::name(TABLE)
		  ->where($where)
		  ->field('id,title,description,category_id,createtime,image,images')
		  ->order('id desc')
		  ->paginate(10);
         //dump($list);die;
		
		$site_title = empty($category_one) ? '新闻中心'.'_'.$this->cache['config']['site_name'] : $category_one[0]['name'].'_新闻中心'.'_'.$this->cache['config']['site_name'];
		$this->assign('list',$list); 
		$this->assign('category',$category_article); 
		$this->assign('category_one',$category_one); 
	    $this->assign('title', $site_title);
		$this->assign('mobile_url',__ROOT__);
		$this->assign('keywords','');
		$this->assign('description','');
        return $this->view->fetch('index/'.SIGN.'_list');
    }
	
	public function viewfeiqi()
	{
	    $bar_code = input('?bar') ? input('bar') : 0;
		$where['bar_code'] = $bar_code;
		$one = Db::name(TABLE)
		  ->where($where)
		  //->field('id,title,description,category_id,author,createtime,content,views')
		  ->find();
		
		$site_title = '金农实业产品追溯平台';
		$this->assign('one',$one); 
	    $this->assign('title',$site_title);
		$this->assign('mobile_url',__ROOT__);
		$this->assign('keywords','');
		$this->assign('description','');
        return $this->view->fetch('led/'.SIGN.'_view');
	}
	
	public function view()
	{
	    $bar_code = input('?bar') ? input('bar') : 0;
		$where['bar_code'] = $bar_code;
		$one = Db::name(TABLE)
		  ->where($where)
		  //->field('id,title,description,category_id,author,createtime,content,views')
		  ->find();
		
		$where2['id'] = !empty($one['basic_id']) ? $one['basic_id'] : $this->cache['site']['site_value']['review_basic'];
		$one_basic = Db::name(TABLE)
		  ->where($where2)
		  ->cache(true)
		  //->field('id,title,description,category_id,author,createtime,content,views')
		  ->find();
		  /*
		dump($one);
		dump($one_basic);
		die;
		*/
		$site_title = '金农实业产品追溯平台';
		$this->assign('one',$one); 
		$this->assign('one_basic',$one_basic); 
	    $this->assign('title',$site_title);
		$this->assign('mobile_url',__ROOT__);
		$this->assign('keywords','');
		$this->assign('description','');
        return $this->view->fetch('led/'.SIGN.'2_view');
	}
	
	public function visitor(){
		if ($this->request->isPost()){
			//$this->request->post(".");
			//dump($this->request->post("."));die;
			$address = $this->request->post("address");
			$map['ip'] = $this->request->post("ip");
			$map['bar'] = $this->request->post("bar");
			$visitor = Db::name('review_visitor')->where($map)->find();
			$map['address'] = $this->request->post("address");
			$map['createtime'] = time();
			if($visitor == 0 && $map['bar'] != 0){
				Db::name('review_visitor')->insert($map);
			}
		}
	}
}
